import React, { Component } from "react";
import { connect } from "dva";
import EditBasic from "../EditBasic";
import EditNumber from "../EditNumber";

const numberManger = {
  marginTop: 16
  // marginBottom: 32
};

@connect(stores => ({
  coldata: stores.user,
  channelNumberData: stores.channelNumberModel
}))
class Edit extends Component {
  state = {
    data: {}
  };

  componentDidMount() {
    this.init();
  }

  init = () => {
    const { location, dispatch } = this.props;
    const channelUserId = location.search.split("?")[1];
    dispatch({
      type: "channelNumber/detailChannel",
      payload: {
        channelUserId
      }
    }).then(res => {
      this.setState({
        data: res.datas
      });
    });
  };

  change = value => {
    const { location, dispatch } = this.props;
    const channelUserId = location.search.split("?")[1];
    const payload = {
      ...value,
      channelUserId
    };
    dispatch({ type: "channelNumber/modChannel", payload }).then(res => {
      if (res.success) {
        this.init();
      }
    });
  };

  onBack = () => {
    const { history } = this.props;
    history.goBack(-1);
    /*
    Modal.confirm({
      title: "是否直接关闭此渠道号？",
      onOk: () => {
        history.push("/messageCenter/channelManager/channelNumber");
      },
      onCancel: () => {}
    });
    */
  };

  render() {
    const { data } = this.state;
    return (
      <div>
        <div>
          <EditBasic data={data} />
        </div>
        <div style={{ ...numberManger }}>
          <EditNumber data={data} change={this.change} />
        </div>
      </div>
    );
  }
}

export default Edit;
